import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get.dart';

import 'translations/en_us.dart';
import 'translations/zh_cn.dart';

class AppTranslations extends Translations {
  @override
  Map<String, Map<String, String>> get keys => {
        'en_US': enUS,
        'zh_CN': zhCN,
      };

  /// 支持的语言
  static const List<Locale> supportedLocales = [
    Locale('en', 'US'),
    Locale('zh', 'CN'),
  ];

  /// 定义代理工厂
  static const List<LocalizationsDelegate> localizationsDelegates = [
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
  ];

  /// 默认语言
  static const fallbackLocale = Locale('zh', 'CN');

  // 获取当前语言
  static Locale? get currentLocale => Get.locale;

  // 切换语言
  static void changeLocale(String languageCode, String? countryCode) {
    final locale = Locale(languageCode, countryCode);
    Get.updateLocale(locale);
  }
}
